<?php require_once('../Connections/agriculture.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];

$maxRows_videoRecordset1 = 10;
$pageNum_videoRecordset1 = 0;

$showType="";

switch($_GET["crop"]){
case "西瓜":$showType="西瓜";break;
case "甜瓜":$showType="甜瓜";break;
case "苦瓜":$showType="苦瓜";break;
case "辣椒":$showType="辣椒";break;
case "豇豆":$showType="豇豆";break;
default:$showType="";
}



if (isset($_GET['pageNum_videoRecordset1'])) {
  $pageNum_videoRecordset1 = $_GET['pageNum_videoRecordset1'];
}
$startRow_videoRecordset1 = $pageNum_videoRecordset1 * $maxRows_videoRecordset1;

$maxRows_videoRecordset1 = 10;
$pageNum_videoRecordset1 = 0;
if (isset($_GET['pageNum_videoRecordset1'])) {
  $pageNum_videoRecordset1 = $_GET['pageNum_videoRecordset1'];
}
$startRow_videoRecordset1 = $pageNum_videoRecordset1 * $maxRows_videoRecordset1;

mysql_select_db($database_agriculture, $agriculture);
$query_videoRecordset1 = "SELECT * FROM video where video_name like '%".$showType."%'";
$query_limit_videoRecordset1 = sprintf("%s LIMIT %d, %d", $query_videoRecordset1, $startRow_videoRecordset1, $maxRows_videoRecordset1);
$videoRecordset1 = mysql_query($query_limit_videoRecordset1, $agriculture) or die(mysql_error());
$row_videoRecordset1 = mysql_fetch_assoc($videoRecordset1);

if (isset($_GET['totalRows_videoRecordset1'])) {
  $totalRows_videoRecordset1 = $_GET['totalRows_videoRecordset1'];
} else {
  $all_videoRecordset1 = mysql_query($query_videoRecordset1);
  $totalRows_videoRecordset1 = mysql_num_rows($all_videoRecordset1);
}
$totalPages_videoRecordset1 = ceil($totalRows_videoRecordset1/$maxRows_videoRecordset1)-1;

$queryString_videoRecordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_videoRecordset1") == false && 
        stristr($param, "totalRows_videoRecordset1") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_videoRecordset1 = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_videoRecordset1 = sprintf("&totalRows_videoRecordset1=%d%s", $totalRows_videoRecordset1, $queryString_videoRecordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>热带农业设施网站视频管理</title>
</head>

<body>

<p><a href="admin.php?crop=西瓜">西瓜</a> <a href="admin.php?crop=甜瓜">甜瓜</a> <a href="admin.php?crop=苦瓜">苦瓜</a> <a href="admin.php?crop=辣椒">辣椒</a> <a href="admin.php?crop=豇豆">豇豆</a></p>



<p><a href="addvideo.php">添加视频</a></p>

<table border="1" cellpadding="0" cellspacing="0">
  <tr>
    <td>ID</td>
    <td>标题</td>
    <td>类型</td>
    <td>发布人</td>
    <td>发布时间</td>
    <td>作物名称</td>
    <td>时期</td>
    <td>信息</td>
    <td>操作</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_videoRecordset1['video_id']; ?></td>
      <td><?php echo $row_videoRecordset1['video_title']; ?></td>
      <td><?php echo $row_videoRecordset1['video_class']; ?></td>
      <td><?php echo $row_videoRecordset1['video_publisher']; ?></td>
      <td><?php echo $row_videoRecordset1['video_time']; ?></td>
      <td><?php echo $row_videoRecordset1['video_name']; ?></td>
      <td><?php echo $row_videoRecordset1['video_period']; ?></td>
      <td><?php echo $row_videoRecordset1['video_information']; ?></td>
      <td><a href="vvideo.php?id=<?php echo $row_videoRecordset1['video_id']; ?>">查看</a><a href="evideo.php?id=<?php echo $row_videoRecordset1['video_id']; ?>">修改</a><a href="admin.php?action=delete&amp;id=<?php echo $row_videoRecordset1['video_id']; ?>" onclick="return okToDelete()">删除</a></td>
    </tr>
    <?php } while ($row_videoRecordset1 = mysql_fetch_assoc($videoRecordset1)); ?>
</table>


<?php 
if($_GET["action"]=="delete"&&$_GET["id"]!=""){
    $deleteSql = "delete from video where video_id=" . $_GET["id"];
    $deleteResult = mysql_query($deleteSql, $agriculture) or die(mysql_error());
    if ($deleteResult) {
        echo "<br>成功删除1条记录";
        echo '<meta http-equiv="refresh" content="1;url=admin.php">';
    }
}
?>
<p>&nbsp;</p>
<p>

                    <script language="javascript">
                        function okToDelete(){
                            if(confirm("确定要删除记录吗?"))
                                return true;
                            else
                                return false;
                        }
                    </script>
					
					
<table width="50%" border="1" cellpadding="0" cellspacing="0">
  <tr>
    <td width="23%" align="center"><a href="<?php printf("%s?pageNum_videoRecordset1=%d%s", $currentPage, 0, $queryString_videoRecordset1); ?>">第一页</a> </td>
    <td width="31%" align="center"><a href="<?php printf("%s?pageNum_videoRecordset1=%d%s", $currentPage, max(0, $pageNum_videoRecordset1 - 1), $queryString_videoRecordset1); ?>">上一页</a> </td>
    <td width="23%" align="center"><a href="<?php printf("%s?pageNum_videoRecordset1=%d%s", $currentPage, min($totalPages_videoRecordset1, $pageNum_videoRecordset1 + 1), $queryString_videoRecordset1); ?>">下一页</a> </td>
    <td width="23%" align="center"><a href="<?php printf("%s?pageNum_videoRecordset1=%d%s", $currentPage, $totalPages_videoRecordset1, $queryString_videoRecordset1); ?>">最后页</a> </td>
  </tr>
</table>

记录 <?php echo ($startRow_videoRecordset1 + 1) ?>-<?php echo min($startRow_videoRecordset1 + $maxRows_videoRecordset1, $totalRows_videoRecordset1) ?> 共 <?php echo $totalRows_videoRecordset1 ?>条
</p> 
<p>
</p>
</body>
</html>
<?php
mysql_free_result($videoRecordset1);
?>